package com.mfl.controller.admin;

import com.mfl.common.PageResult;
import com.mfl.common.Result;
import com.mfl.pojo.dto.TestExamTopicDTO;
import com.mfl.pojo.dto.TestExamTopicPageQueryDTO;
import com.mfl.pojo.vo.TestExamTopicVO;
import com.mfl.service.TestExamTopicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminTestExamTopicController")
@RequestMapping("/cky/admin/testExamTopic")
@Slf4j
public class TestExamTopicController {

    @Autowired
    private TestExamTopicService testExamTopicService;

    /**
     * 分页查询试卷题目
     * @param testExamTopicPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(TestExamTopicPageQueryDTO testExamTopicPageQueryDTO){
        log.info("分页查询试卷题目：{}", testExamTopicPageQueryDTO);
        PageResult pageResult = testExamTopicService.page(testExamTopicPageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 添加试卷题目
     * @param testExamTopicDTO
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody TestExamTopicDTO testExamTopicDTO){
        log.info("添加试卷题目：{}", testExamTopicDTO);
        testExamTopicService.insert(testExamTopicDTO);
        return Result.success("添加成功");
    }

    /**
     * 批量删除试卷题目
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestParam List<Integer> ids){
        log.info("批量删除试卷题目：{}", ids);
        testExamTopicService.batchDelete(ids);
        return Result.success("删除成功");
    }

    /**
     * 根据id查询试卷题目
     * @param id
     * @return
     */
    @GetMapping("/getTestExamTopicById")
    public Result<TestExamTopicVO> getTestExamTopicById(@RequestParam Integer id, @RequestParam Integer testExamId){
        log.info("根据id查询试卷题目：id:{},testExamId:{}", id, testExamId);
        TestExamTopicVO testExamTopicVO = testExamTopicService.getTestExamTopicById(id, testExamId);
        return Result.success("", testExamTopicVO);
    }

    /**
     * 修改试卷题目
     * @param testExamTopicDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody TestExamTopicDTO testExamTopicDTO){
        log.info("修改试卷题目：{}", testExamTopicDTO);
        testExamTopicService.update(testExamTopicDTO);
        return Result.success("修改成功");
    }
}
